package com.gmj.controller;


import com.gmj.entity.Teacher;
import com.gmj.entity.Workhome;
import com.gmj.service.IWorkhomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmj
 * @since 2022-01-29
 */
@RestController
@RequestMapping("/workhome")
public class WorkhomeController {
    @Autowired
    private IWorkhomeService ws;
    @GetMapping("/selectAll")
    public List<Workhome> selectAll(){
        return ws.list();
    }
    @PostMapping("/add")
    public void add(@RequestBody Workhome workhome, HttpSession session){
        workhome.setSubmitDate(LocalDateTime.now());
        Teacher teacher = (Teacher)session.getAttribute("user");
        workhome.setTid(teacher.getId());
        ws.save(workhome);
    }
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") int id){
        ws.removeById(id);
    }
}

